package com.bhy702.generator.builder;

import com.bhy702.generator.builder.util.StringUtil;
import lombok.Data;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: brbai
 * @create: 2019-12-26 11:13:42
 * @description: 模板参数
 */
@Data
public class TplProperties {

    private String basePath;
    private String rootPackage;
    private String tableName;
    private List<Column> columnList;

    private Map<String,Object> params = new HashMap();;
    /**
     * 表名格式转换
     * xxx_yyy->XxxYyy
     */
    private String className;

    /**
     * 表名格式转换
     * xxx_yyy->xxxYyy
     */
    private String propertyName;

    public TplProperties(String basePath, String rootPackage, String tableName, List<Column> columnList) {
        this.basePath = basePath;
        this.rootPackage = rootPackage;
        this.tableName = tableName;
        this.columnList = columnList;
    }

    public TplProperties(String rootPackage, String tableName, List<Column> columnList) {
        this.rootPackage = rootPackage;
        this.tableName = tableName;
        this.columnList = columnList;
    }

    public String getClassName() {
        return StringUtil.mapTableNameToClassName(tableName);
    }
    public String getPropertyName() {
        return StringUtil.mapTableNameToPropertyName(tableName);
    }

    public void setParam(String key,Object value) {
        this.params.put(key,value);
    }

    public String getBasePath() {
        if(basePath == null){
            //未在properties文件中设置代码生成路径时，代码默认生成在此项目下
            return System.getProperty("user.dir") + "/src";
        }
        return basePath;
    }
}
